import 'package:freedom/page/mahjong/bloc/room_info.dart';
import 'package:freedom/page/mahjong/util/abstrcat_mahjong_func.dart';
import 'package:freedom/page/mahjong/util/mahjong_util.dart';

class WzMahjongFunc extends AbstractMahjongFunc {
  List<int> checkHuCard(List<int> allCard, RoomInfo? roomInfo) {
    List<int> allCardTemp = List.from(allCard);
    // 无论用户是什么牌 顶多向左右扩1张
    List<int> preSelections = [];
    var maxRedundant = 1;
    for (var card in allCardTemp) {
      var min = 1, max = 9;
      var maxRedundantTemp = maxRedundant;
      if (card > 10 && card < 20) {
        min = 11;
        max = 19;
      } else if (card > 20 && card < 30) {
        min = 21;
        max = 29;
      }
      var cardTemp = card;
      while (cardTemp >= min && maxRedundantTemp >= 0) {
        if (!preSelections.contains(cardTemp)) {
          preSelections.add(cardTemp);
        }
        cardTemp--;
        maxRedundantTemp--;
      }
      maxRedundantTemp = maxRedundant;
      cardTemp = card;
      while (cardTemp <= max && maxRedundantTemp >= 0) {
        if (!preSelections.contains(cardTemp)) {
          preSelections.add(cardTemp);
        }
        cardTemp++;
        maxRedundantTemp--;
      }
    }
    List<int> result = [];
    for (var element in preSelections) {
      if (MahjongUtil.canHu(List.from(allCard)..add(element), 0)) {
        result.add(element);
      }
    }
    return result;
  }
}
